import { useTable, LIST_TYPE } from '@crud/index';
import { getSkuList } from '@/api/crm-kgj/sku';
// import MockService from '@/services/mock';
import dayjs from 'dayjs';

// 商品状态
export const statusOptions: any = [
  { label: '不限', value: '' },
  { label: '已失效', value: 3 },
  { label: '上架', value: 1 },
  { label: '下架', value: 2 }
];

// 管理类型
export const relevanceOptions: any = [
  { label: '不限', value: '' },
  { label: '商家', value: 1 },
  { label: '团长', value: 2 }
];

export const statusStyleMap: Record<string, any> = {
  待发布: '#909399',
  已发布: '#67C23A',
  定时发布: '#E6A23C'
};
// 表格
export const useTableList = (options: any = {}) => {
  const columns = [
    { type: 'selection', width: 55, fixed: 'left' },
    { label: '商品信息', prop: 'cover', minWidth: 240, render: 'cover' },
    { label: '活动ID', prop: 'activity_id', minWidth: 120, type: 'copy', render: 'activity' },
    { label: '店铺', prop: 'shop', minWidth: 120, render: 'shop', howOverflowTooltip: true, align: 'center' },
    { label: '价格', prop: 'price', minWidth: 120, type: 'priceCent', sortable: true, align: 'right' },
    { label: '佣金', prop: 'colonel_cos_ratio', minWidth: 120, render: 'payment', sortable: true, align: 'right' },
    { label: '服务费', prop: 'service_ratio', minWidth: 120, type: 'percent', sortable: true, align: 'right' },
    { label: '出单达人数', prop: 'order_author_count', minWidth: 120, sortable: true, align: 'right' },
    { label: '商品状态', prop: 'status', minWidth: 120, render: 'status', align: 'center' },
    { label: '关联橱窗数', prop: 'relative', minWidth: 120, render: 'relative', align: 'center', sortable: false },
    { label: '上架时间', prop: 'put_time', minWidth: 180, render: 'put_time', sortable: true, align: 'center' },
    { label: '操作', align: 'center', width: 200, render: 'actions', fixed: 'right' }
  ];

  return useTable({
    type: LIST_TYPE.CONTENT, // 待修改
    params: {
      // article_type: -1,
      // status: '',
      title: undefined,
      _timeArr: [],
      author: undefined,
      user_name: undefined,
      is_related: 1,
      colonel_type: undefined
    },
    columns,
    getParams: ({ _timeArr = [], ...params }) => {
      // 处理时间参数
      if (_timeArr?.length) {
        params.begin_time = dayjs(_timeArr[0]).startOf('day').format('X');
        params.end_time = dayjs(_timeArr[1]).endOf('day').format('X');
      }
      return {
        ...params
        // ...formatParamsSelectVal(
        //   [
        //     ['status', -1],
        //     ['article_type', -1]
        //   ],
        //   params
        // )
      };
    },
    getList: ({ params, data }: any) => {
      // const mockApi = () => {
      //   return new Promise((resolve) => {
      //     setTimeout(() => {
      //       resolve(MockService.mock({
      //         id: '@index',
      //         cover: '@picture',
      //         title: '@name:product',
      //         colonel_name: '@name',
      //         product_id: '@id',
      //         shop_name: '@name:shop',
      //         shop_score: '@state:5:1',
      //         price: '@float',
      //         is_high_cos_ratio: '@boolean',
      //         cos_ratio: '@percent',
      //         colonel_cos_ratio: '@percent',
      //         status: '@state:3:1',
      //         put_time: '@timestamp',
      //         shop_count: '@integer',
      //         url: '@url'
      //       }, params));
      //     }, 500);
      //   });
      // };
      // return mockApi();
      return getSkuList({ params, data });
    }
  });
};
